package org.sems.sems.service.impl;

import org.sems.sems.Mapper.DataGwdmkMapper;
import org.sems.sems.Mapper.YqljkMapper;
import org.sems.sems.entity.Yqljk;
import org.sems.sems.service.YqljkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
@Service
public class YqljkServiceImpl implements YqljkService {

    @Autowired
    private YqljkMapper yqljkMapper;


    /**
     * 添加一条数据
     * @param yqljk
     * @return
     */
    @Override
    public Map<String, Object> addYqljk(Yqljk yqljk) {
        Map<String, Object> dataGwdmk = new HashMap<>();
        try {
            if ( yqljkMapper.InsertYqljk(yqljk)!= 0) {
                dataGwdmk.put("code", 200);
                dataGwdmk.put("msg", "success");
                dataGwdmk.put("result", true);
            } else {
                dataGwdmk.put("code", 504);
                dataGwdmk.put("msg", "database error");
                dataGwdmk.put("result", false);
            }
        } catch (Exception e) {
            e.printStackTrace();
            dataGwdmk.put("code", 500);
            dataGwdmk.put("msg", "server error");
            dataGwdmk.put("result", false);
        }
        return dataGwdmk;
    }

    /**
     * @return
     */
    @Override
    public Map<String, Object> getAllYqljk() {
        Map<String, Object> result = new HashMap<>();
        try {
            // TODO: 获取单位规模库数据
            result.put("code", 200);
            result.put("msg", "success");
            result.put("data", yqljkMapper.getALLYqljk());
            result.put("result", true);
        } catch (Exception e) {
            result.put("code", 500);
            result.put("msg", e.getMessage());
            result.put("data", null);
            result.put("result", false);
            e.printStackTrace();
        }
        return result;
    }

    /**
     * @param id
     * @return
     */
    @Override
    public Map<String, Object> deleteYqljk(int id) {
        Map<String, Object> dataGwdmk = new HashMap<>();
        try {
            if ( yqljkMapper.deleteYqljk(id)!= 0) {
                dataGwdmk.put("code", 200);
                dataGwdmk.put("msg", "success");
                dataGwdmk.put("result", true);
            } else {
                dataGwdmk.put("code", 504);
                dataGwdmk.put("msg", "database error");
                dataGwdmk.put("result", false);
            }
        } catch (Exception e) {
            e.printStackTrace();
            dataGwdmk.put("code", 500);
            dataGwdmk.put("msg", "server error");
            dataGwdmk.put("result", false);
        }
        return dataGwdmk;
    }

    /**
     * @param yqljk
     * @return
     */
    @Override
    public Map<String, Object> updateYqljk(Yqljk yqljk) {
        Map<String, Object> dataGwdmk = new HashMap<>();
        try {
            if ( yqljkMapper.updateYqljk(yqljk)!= 0) {
                dataGwdmk.put("code", 200);
                dataGwdmk.put("msg", "success");
                dataGwdmk.put("result", true);
            } else {
                dataGwdmk.put("code", 504);
                dataGwdmk.put("msg", "database error");
                dataGwdmk.put("result", false);
            }
        } catch (Exception e) {
            e.printStackTrace();
            dataGwdmk.put("code", 500);
            dataGwdmk.put("msg", "server error");
            dataGwdmk.put("result", false);
        }
        return dataGwdmk;
    }
}
